import { defineConfig } from "vite";
import vue from "@vitejs/plugin-vue";
import { fileURLToPath, URL } from "node:url";
import Components from "unplugin-vue-components/vite";
import { VantResolver } from "unplugin-vue-components/resolvers";
// import vueDevTools from "vite-plugin-vue-devtools";
// https://vite.dev/config/
// http://172.26.8.168:8080
const baseURL = "http://localhost:8080";
export default defineConfig({
  plugins: [
    vue(),
    Components({
      resolvers: [VantResolver()],
    }),
    // vueDevTools(),
  ],
  // base: "/topicbar",
  resolve: {
    alias: {
      "@": fileURLToPath(new URL("./src", import.meta.url)),
    },
  },
  server: {
    proxy: {
      "/api": {
        target: baseURL, // 后端 API 地址
        changeOrigin: true, // 修改请求头中的 Origin，避免 CORS 问题
        rewrite: (path) => path.replace(/^\/api/, ""), // 重写路径，去掉 /api 前缀
        secure: false, // 如果目标是 https 且无合法证书，需设置为 false
      },
    },
  },
  build: {
    sourcemap: true,
  },
});
